/*
 * @File: ieee1905.h
 *
 * @Abstract: IEEE 1905.1 control protocol header file.
 *
 * @Notes:
 *
 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
 * All rights reserved.
 * Qualcomm Atheros Confidential and Proprietary.
 *
 */

#ifndef ieee1905__h /*once only*/
#define ieee1905__h

#include "ieee1905_defs.h"

/*
 * Basic enumerations
 */
typedef enum
{
    IEEE1905_OK = 0,
    IEEE1905_NOK = -1,

} IEEE1905_STATUS;

typedef enum
{
    IEEE1905_FALSE = 0,
    IEEE1905_TRUE = !IEEE1905_FALSE

} IEEE1905_BOOL;

/*
 * Events generated by this module
 */
typedef enum ieee1905Event_e
{
    IEEE1905_EVENT_TOPOLOGY = 0,
    IEEE1905_EVENT_VENDOR_SPECIFIC,
    IEEE1905_EVENT_LINK_METRIC,
    IEEE1905_EVENT_AP_AUTOCONFIGURATION,
    IEEE1905_EVENT_ACK,
    IEEE1905_EVENT_AP_CAP,
    IEEE1905_EVENT_MAP_POLICY,
    IEEE1905_EVENT_CHANNEL_PREFERENCE,
    IEEE1905_EVENT_CHANNEL_SELECTION,
    IEEE1905_EVENT_OPERATING_CHANNEL,
    IEEE1905_EVENT_CLIENT_CAPABILITY,
    IEEE1905_EVENT_AP_METRICS,
    IEEE1905_EVENT_ASSOC_STA_LINK_METRIC,
    IEEE1905_EVENT_UNASSOC_STA_METRIC,
    IEEE1905_EVENT_BEACON_METRICS,
    IEEE1905_EVENT_COMBINED_INFRASTRUCTURE_METRICS,
    IEEE1905_EVENT_CLIENT_STEERING,
    IEEE1905_EVENT_HIGHER_LAYER_PAYLOAD,
    IEEE1905_EVENT_BACKHAUL_OPTIMIZATION,

    IEEE1905_EVENT_LAST /* Must be the last */

} ieee1905Event_e;

/*
 * Maximum supported interfaces
 */
#define IEEE1905_MAX_INTERFACES      16

/*
 * Callback format for incoming IEEE1905.1 packets
 */
typedef void(*ieee1905ReceiveCallback_f)( ieee1905Event_e event, u_int8_t* frame, u_int32_t len );

/*
 * Callback format for relaying IEEE1905.1 packets
 * Should be initialized only by Hybrid Daemon!
 */
typedef void(*ieee1905RelayCallback_f)( u_int8_t* frame, u_int32_t len );


/*-------------------------------------------------------------------*/
/*---------------------------IEEE1905 API----------------------------*/
/*-------------------------------------------------------------------*/


/*
 * IEEE 1905.1 Module API
 */

/*
 * ieee1905TLVTypeFind - Find a TLV in the message
 */
ieee1905TLV_t* ieee1905TLVTypeFind( ieee1905TLV_t* TLV, u_int8_t type );

/*
 * ieee1905MessageBufferGet - Get a pointer to the message buffer
 */
u_int8_t *ieee1905MessageBufferGet( void );

/*
 * ieee1905MessageIdUpdate - Update an IEEE 1905.1 message identifier
 * @frame: Address of the frame
 * @mid: Message ID
 */
IEEE1905_STATUS ieee1905MessageIdUpdate( u_int8_t *frame, u_int16_t mid );

/*
 * ieee1905MessageSetup - Setup a new IEEE 1905.1 message
 * @frame: Address of the frame
 * @type: Message type
 * @mid: Message ID
 * @fid: Fragment ID
 * @flags: Message flags
 */
IEEE1905_STATUS ieee1905MessageSetup( u_int8_t *frame, ieee1905MessageType_e type, u_int16_t mid, u_int8_t fid, u_int8_t flags );

/*
 * ieee1905MessageSetup - Send an ieee1905 message
 * @ifaceName: Specify the tx interface name
 * @frame: Address of the frame
 * @len: Length of this frame should be sent
 * @src: Source address or NULL to send using the selected interface MAC address
 * @dest: Destination address or NULL to send as Multicast message
 */
IEEE1905_STATUS ieee1905MessageSend( const char *ifaceName, u_int8_t *frame, u_int32_t len,
                                     const struct ether_addr *src, const struct ether_addr *dest );

#define ieee1905MessageBufferSizeGet() \
    ( ETH_FRAME_LEN )

#define ieee1905MessageContentGet( _frame ) \
    ( ( (ieee1905Message_t *) _frame )->content )

#define ieee1905MessageMaxContentSizeGet() \
    ( IEEE1905_CONTENT_MAXLEN )

#define ieee1905GetRxInterface( _frame ) \
    ( ( (ieee1905Message_t *) _frame )->ieee1905Header.reserved )

/*
 * ieee1905GetContentSize - Get the content size of a message
 */
int32_t ieee1905GetContentSize( ieee1905Message_t *message, u_int32_t contentLenOnWire );

/*
 * ieee1905IsAgedOutGeneric - Compare two time stamps against timeout and return true if aged out
 */
IEEE1905_BOOL ieee1905IsAgedOutGeneric( struct timeval *t_old, struct timeval *t_now, u_int32_t timeout );

/*
 * ieee1905Init - Module init function
 * @bridgeName: Specify the bridge (RX) interface
 * @ieee1905ReceiveCallback: Callback to call when a packet is received
 * @ieee1905RelayCallback: Callback to call for packet relaying (for hyd only!)
 *                         other clients must use NULL.
 */
void ieee1905Init( const char *bridgeName, ieee1905ReceiveCallback_f ieee1905ReceiveCallback, ieee1905RelayCallback_f ieee1905RelayCallback );

#endif /* ieee1905__h */
